$(function () {
  // wzERP.Contract.init();
  // wzERP.Contract.turnPage();//分页
  wzERP.Common.inlineDate('#date1', '#date2');  //联动日期
});

//表单模板数据请求
demo(1)
// 获取当前页面内容
function demo(curr, num, searchKey, custName, startDate, endDate, status) {
  //curr:当前页
  //num:每页显示条数
  //searchKey:搜索内容
  //startDate:开始时间
  //endDate:结束时间
  $.get('/finance/erpReceivables/queryPage', {
    current: curr || 1,
    pageSize: num || 10,
    searchKey: searchKey,
    startDate: startDate,
    endDate: endDate,
    custName: custName,
    status: status
  }, function (content) {
    //获取内容显示到模板上
    $('#LinelistAreaData').html(template('LinelistArea', content.data))
    // 分页
    layui.use(['laypage', 'layer'], function () {
      var laypage = layui.laypage;
      laypage({
        cont: 'turn-page',
        curr: curr || 1,
        pages: content.data.pages,
        skin: '#457fe6',
        skip: true,
        jump: function (obj, first) {
          var num = $('#LinenumberOf select').val()
          if (!first) {
            demo(obj.curr, num);
          }
        }
      });
    });
  })
}
//查询客户列表
querCustList();
function querCustList() {
  $.get('/finance/erpAccountReceivable/queryCustGroupList', {},
      function (result) {
        var content = result.data;
        var objResult = [];

        for (var i = 0; i < content.length; i++) {
          var obj = content[i];
          var newObj = {};
          newObj.title = obj.custName;
          objResult.push(newObj);
        }
        $('#search')
        .search({
          source: objResult,
          searchFullText: false
        })

      })
}

// 每页显示条数
$('#LinenumberOf ').on('click', function () {
  //获取当前页数
  var page = $('.layui-laypage-skip').val()
  // 获取表单时间
  var content = $("#LinesearchForm").serialize()
  //使用方法分割取出
  var contentS = content.split('&')
  var obj = {}
  for (var i = 0; i < contentS.length; i++) {
    var con = contentS[i].toString()
    var son = con.split('=')
    obj[son[0]] = son[1]
  }
  //获取当前每页应该显示条数
  var num = $('#LinenumberOf select').val()
  //获取搜索框内容
  var searchKey = $('#searchKey').val()
  var custName = $('#custName').val()
  //获取分割好的起止时间
  var startDate = obj.startDate
  var endDate = obj.endDate
  var status = $('#status').val();
  if (status == 'all') {
    status = ''
  }
  demo(page, num, searchKey, custName, startDate, endDate, status)
})

//查询业务
$("#LinetimeA").on('click', function () {
  // 获取表单时间
  var content = $("#LinesearchForm").serialize()
  //使用方法分割取出
  var contentS = content.split('&')
  var obj = {}
  for (var i = 0; i < contentS.length; i++) {
    var con = contentS[i].toString()
    var son = con.split('=')
    obj[son[0]] = son[1]
  }
  //获取当前每页应该显示条数
  var num = $('#LinenumberOf select').val()
  //获取客户搜索框内容
  var searchKey = $('#searchKey').val()
  var custName = $('#custName').val()//客户编号
  //获取分割好的起止时间
  var startDate = obj.startDate
  var endDate = obj.endDate
  var status = $('#status').val()//业务类型
  if (status == 'all') {
    status = ''
  }
  //获取搜索内容
  query(1, num, searchKey, startDate, endDate, custName, status)
  function query(curr, num, searchKey, custName, startDate, endDate, status) {
    $.get('/finance/erpReceivables/queryPage', {
      current: curr || 1,
      pageSize: num || 10,
      searchKey: searchKey,
      startDate: startDate,
      endDate: endDate,
      custName: custName,
      status: status
    }, function (content) {
      //获取内容显示到模板上
      $('#LinelistAreaData').html(template('LinelistArea', content.data))
      // 分页
      layui.use(['laypage', 'layer'], function () {
        var laypage = layui.laypage;
        laypage({
          cont: 'turn-page',
          curr: curr || 1,
          pages: content.data.pages,
          skin: '#457fe6',
          skip: true,
          jump: function (obj, first) {
            var num = $('#LinenumberOf select').val()
            if (!first) {
              query(obj.curr, num, searchKey, startDate, endDate);
            }
          }
        });
      });
    })
  }

  return false
})

$('#LineService').on('click', function () {
  $('#LineSelectionService').css('display', 'block')
})
$('#LineDisappear').on('click', function () {
  $('#LineSelectionService').css('display', 'none')
})
$('#LineClose').on('click', function () {
  $('#LineSelectionService').css('display', 'none')
})

//订单详情
$('#LinelistAreaData').on('click', '#LineDetails', function () {
  $('#LineDetailsToModal').modal({
    closable: false,
    transition: 'fade'
  }).modal('show')
})

//编辑订单
$('#LinelistAreaData').on('click', '#LineEdit', function () {
  $('#LineAddToModal').modal({
    closable: false,
    transition: 'fade'
  }).modal('show')
})

//审核订单
$('#LinelistAreaData').on('click', '#LineExamine', function () {
  $('#LineExamineToModal').modal({
    closable: false,
    transition: 'fade'
  }).modal('show')
})

//分单
$('#LinelistAreaData').on('click', '#LinePolicy', function () {
  $('#LinePolicyToModal').modal({
    closable: false,
    transition: 'fade'
  }).modal('show')
})

//立案
$('#LinelistAreaData').on('click', '#LineFiling', function () {
  $('#LineFilingToModal').modal({
    closable: false,
    transition: 'fade'
  }).modal('show')
})

